package demo8;

public class Fabric {
    public FabricWithMemo createFabricWithMemo(){
        return new FabricWithMemo();
    }
    /**
     *  compute the val ,the algs is :
     *  f(n)=f(n-1)+f(n-2)
     *  f5=f4+f3
     *
     */
    public int fabric(int n){
        if(n==0) return 0;
        if(n==1) return 1;
        return fabric(n-1) + fabric(n-2);
    }
    public class FabricWithMemo{
        // f5 => counter=5;
        public int fabricWithMemoInitAndStart(int n){
            return fabricWithMemo(n,new int[n+1]);
        }
        public int fabricWithMemo(int n, int[] memo){
            if(n==0) return 0;
            if(n==1) return 1;
            if(memo[n]==0){
                memo[n]=fabricWithMemo(n-1,memo) + fabricWithMemo(n-2,memo);
            }
            return memo[n];
        }
    }


}
